#include "nanod.h"

#ifndef __NANOD_HTTP__
#define __NANOD_HTTP__


#define NANOD_HTTP_READ_SIZE 1024
#define NANOD_HTTP_MAX_HEADER_SIZE 8192
#define NANOD_HTTP_FILE_READ 8192
#define NANOD_HTTP_FILE_SEND 1024 

typedef struct
{
  int   socket;
  
  // http client request header info
  nstr_t *action;
  // path of the requiered file
  nstr_t *path;
  // http proto (1.0, 1.1, ...)
  nstr_t *proto;

  nstr_t *host;

  nstrt_t *head_keys;
  nstrt_t *head_values;
      
  // store the incoming data
  nstr_t *buff_in;
  // end of the header ("\r\n\r\n")
  int   header_end;
  
  // output buffer
  nstr_t *buff_out;
} http_request_t;


char    *http_make_current_date(char *buffer, int size);
nstr_t  *http_make_header(http_request_t *request
                          , int status_code, const char *content_type
                          , int content_size, nstr_t *msg);
void    http_send_error(int status_code, http_request_t *request);
void    http_get_header_first_line(http_request_t *request);
int     http_get_header(http_request_t *request);
int     http(void *params, int socket);
nstr_t  *http_make_directory_line(nstr_t *listing, int type, int pos
                                  , nstr_t *host, nstr_t *path
                                  , const char *name);
int     http_send_directory(http_request_t *request);
int     http(void *params, int socket);








#endif

